/*
 * Skill.h
 *
 *  Created on: 08.11.2010
 *      Author: 123
 */

#ifndef SKILL_H_
#define SKILL_H_
#include "Char.h"
#include "Timer.h"

extern sHero Char[2];

class SkillImprove {
	int point[10];
	int FreePoint;
	int index;
	Timer *time;
	bool DrawVar;

public:

	std::string info[10];
	std::string MoreInfo[10];
	SkillImprove() {
		index = 0;
		FreePoint = 0;
		DrawVar=1;
		time= new Timer(1.0);
		time->startTimer();
	}
	~SkillImprove(){
		delete time;
	}
	void AddFree(int a) {
		FreePoint += a;
	}
	void Load(const char * name) {
		char line[32];

		FILE * fd = fopen(name, "r");
		if (!fd)
			fprintf(stderr, "fd load fail");
		for(int i=0;i<10;i++){
			fgets(line, 32, fd);
			this->info[i]=line;
		}
		for(int i=0;i<10;i++){
			fgets(line, 32, fd);
			this->MoreInfo[i]=line;
		}




	}
	void Control() {
		if (osl_keys->pressed.down && index < 9){
			index++;
			time->resetTimer();
		}
		if (osl_keys->pressed.up && index > 0){
			index--;
			time->resetTimer();
		}
		if (osl_keys->pressed.cross && FreePoint > 0) {
			switch (index) {
			case 0:
				Char[0].healthmax += 50;
				break;

			}
			point[index] += 1;
			FreePoint -= 1;
			time->resetTimer();
		}
		if(time->getTimer()>1.0){
			oslDrawFillRect(50, 30, 300, 250, RGB(244,196,48));
			pgeFontActivate(nash);
			pgeFontPrintf(nash, 250, 65, BLACK, "%s",this->MoreInfo[index].c_str());
			DrawVar=false;

		}
		if(osl_keys->pressed.circle && !DrawVar){
			osl_keys->pressed.circle=0;
			time->resetTimer();
		}
	}
	void Draw() {
		if(this->DrawVar){
			oslDrawFillRect(50, 30, 300, 250, RGB(244,196,48));
			pgeFontActivate(nash);
			for (int i = 0; i < 10; i++) {
				//	oslDrawFillRect(50,50+i*16,200,50+i*16+16,);
				oslDrawRect(50, 50 + i * 20, 300, 50 + i * 20 + 20, GREEN);
				pgeFontPrintf(nash, 52, 65 + i * 20, GREEN, "%s", info[i].c_str());
				pgeFontPrintf(nash, 250, 65 + i * 20, BLACK, "%d", point[i]);


			}
			oslDrawRect(50, 50 + index * 20, 300, 50 + index * 20 + 20, RED);
			oslDrawRect(50, 30, 300, 50, GREEN);
			pgeFontPrintf(nash, 50, 45, BLACK, "free point%d", FreePoint);
		}
	}
};
extern SkillImprove Skill;

#endif /* SKILL_H_ */
